﻿(function ($) {
    'use strict';
    var rootWeb;
    
    $(document).ready(function () {
        
        var clientContext = SP.ClientContext.get_current();
        rootWeb = clientContext.get_site().get_rootWeb();
        
        clientContext.load(rootWeb);
        clientContext.executeQueryAsync(onRequestSucceeded, onRequestFailed);
        
        function onRequestSucceeded() {
            var $tree = $("#siteTree").sptree({
                "checkbox": {
                    "three_state": false
                },
                "sptree": {
                    rootweburl: rootWeb.get_url(),
                    filterlistsByTemplate: 106,
                    selectable: 'none',
                    checkable: 'lists',
                    useInSPApp: true
                }
            }).bind("select_node.jstree", function (event, data) {
                var node = data.node;
                alert("select " + node.data.url);
            });
        }
        function onRequestFailed(sender, args) {
            alert('Error: ' + args.get_message());
        }

    });
    

}(jQuery));